package cn.edu.sdjzu.xg2103.controller.basic;

import cn.edu.sdjzu.xg2103.entity.Department;
import cn.edu.sdjzu.xg2103.exception.BysjException;
import cn.edu.sdjzu.xg2103.service.DepartmentService;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/DepartmentUpdate.ctl")
public class DepartmentUpdateCtl extends HttpServlet {
    protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        JSONObject message_jsonObj = new JSONObject();
        response.setContentType("application/json;charset=UTF-8");
        try{
            Department department = new Department(1);
            boolean updated = DepartmentService.getInstance().update(department);
            message_jsonObj.put("updated",updated);
            message_jsonObj.put("records","修改了一条信息");
            //分页获得所有学院
            //响应message_jsonObj到前端
            response.getWriter().println(message_jsonObj);
        }catch (BysjException e){
            message_jsonObj.put("message",e.getMessage());
            response.getWriter().println(message_jsonObj);
            e.getStackTrace();
        }catch (SQLException e){
            message_jsonObj.put("message","数据库操作异常");
            response.getWriter().println(message_jsonObj);
            e.getStackTrace();
            message_jsonObj.put("message",e.getMessage());
            response.getWriter().println(message_jsonObj);
        }catch (Exception e){
            message_jsonObj.put("message","网络异常");
            response.getWriter().println(message_jsonObj);
            e.getStackTrace();
            System.out.println(e.getMessage());

        }
    }

}
